package _02_链表;

public class _141_环形链表 {

    // 快慢指针
    public boolean hasCycle(ListNode head) {
        if (head == null) return false;
        ListNode slow = head;
        ListNode fast = head;
        while (fast.next != null && fast.next.next != null) {
            // 块指针走两步
            fast = fast.next.next;
            // 慢指针走一步
            slow = slow.next;
            if (fast == slow)
                return true;
        }
        return false;
    }

}
